<template>
	<view class="content" :style="{paddingTop:headerArea.status_height+'px'}">
		<view class="header" :style="{height:headerArea.title_height+'px'}">
			<view class="home" v-if="type === 'home'"> 
				<image class="logo" src="../../static/images/home/logo@2x.png" />
			 </view>
			<view class="nothing" v-else-if="type === 'nothing'" >  </view>
			<view class="search" v-else-if="type === 'search'" > 
				<image v-if="title!=='我的订单'" @click="toBack" class="back-arrow" src="@/static/images/tabBar/backArrow@2x.png" mode=""></image> 
				<view class="search-content">
					<image class="search-img" src="@/static/images/home/search@2x.png" />
					<input type="text" class="desc" placeholder="搜索更多美食" v-model="searchContent" />
					<image class="search-button" @click="searchClick" src="@/static/images/home/searchButton@2x.png" />
				</view>
			</view>
			<view class="commen" v-else-if="type === 'commen'" >
				<image v-if="title!=='我的订单'" @click="toBack" class="back-arrow" src="@/static/images/tabBar/backArrow@2x.png" mode=""></image>
				<text class="desc">{{ props.title }}</text>
			</view>
		</view>
	</view>
</template>
 
<script setup>
import { computed,ref } from "vue";
	import request from "@/Api/request.js"
	const props = defineProps({
		// 页面的顶部标题
		title:{
			type:String,
			required:true
		},
		// 所有页面顶部大致为四种,commen,home,search,nothing
		type:{
			type:String,
			required:true
		},

	})
		
	const headerArea = computed(()=> {
		let area = uni.getSystemInfoSync();
		// #ifdef MP-WEIXIN
		let menu = uni.getMenuButtonBoundingClientRect();
		return {
	    status_height: area.statusBarHeight,
		title_height: menu.height + (menu.top - area.statusBarHeight) * 2,
		menuLeft: menu.left
		};
		// #endif
		// #ifndef MP-WEIXIN
		return {
		status_height: area.statusBarHeight,
		title_height: uni.upx2px(80),
		menuLeft: 0
		};
		// #endif
	})

	//搜索框内容绑定
	let searchContent = ref("")
	function toBack(){
		uni.navigateBack({
			delta:1
		})
	}

	function searchClick(){
		if(!searchContent.value){
			return 
		}
		request({
			url:"/search",
			method:"GET",
			params:{
				dineIn:true,	
				offlinePickUp:false,
				orderType:"all",
				takeaway:false,
				keyword:searchContent.value
			}
		}).then((res)=>{
			console.log(res);
			uni.navigateBack()
		})
	}

</script>
 
<style lang="scss" scoped>
	.content
	
	.back-arrow{
		width: 48rpx;
		height: 48rpx;
		left: 0;
		vertical-align: -3rpx;
	}
	
	.content{
		width: 100%;
		z-index: 0;
		position: relative;
	}

	.header{
		display: flex;
		align-items: center;
		
	}
	
	.home{
		.logo{
			width: 148rpx;
			height: 56rpx;
			z-index: 9;
		}
	}
	
	.nothing{
		
	}
	
		
	.search{
		padding: 12rpx;
		width: 100%;
		display: flex;
		align-items: center;
		gap: 24rpx;
		
		.search-content{
				width: 428rpx;
				height: 64rpx;	
				display: flex;
				justify-content: center;
				align-items: center;
				background: #fff;
				border-radius: 36rpx;
				position: relative;
				.search-img{
					width: 40rpx;
					height: 40rpx;
					position: absolute;
					left: 32rpx;
				}
				.desc{
					width: 60%;
					color: #999;
					font-size: 26rpx;
					font-weight:400;
					position: absolute;
					left: 80rpx;
				}
				.search-button{
					width: 120rpx;
					height: 56rpx;
					position: absolute;
					right: 4rpx;
				}
			}
	}
	
	.commen{
		width: 100%;
		text-align: center;
		color: #000;
		font-size: 17px;
		font-weight: 600;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		
		.back-arrow{
			position: absolute;
			left: 0;
		}
	}
	
</style>
